package cst.neu.yuejian_31.model;

import java.util.List;

import cst.neu.yuejian_31.bean.CollectActivityBean;
import cst.neu.yuejian_31.iface.CollectActivityIface;
import cst.neu.yuejian_31.iface.CollectActivityListener;
import cst.neu.yuejian_31.service.CollectActivityService;
import cst.neu.yuejian_31.Common.Constant;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by xxe on 2017/11/3.
 */

public class CollectActivityModel implements CollectActivityIface {
    private Retrofit retrofit;
    public CollectActivityModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getCollectActivity(String userId, final CollectActivityListener collectActivityListener) {
        CollectActivityService collectActivityService=retrofit.create(CollectActivityService.class);
        Call<List<CollectActivityBean>>call=
                collectActivityService.getCollectActivity(userId);
        call.enqueue(new Callback<List<CollectActivityBean>>() {
            @Override
            public void onResponse(Call<List<CollectActivityBean>> call, Response<List<CollectActivityBean>> response) {
                if(response.isSuccessful()&&response.body()!=null){
                    collectActivityListener.onSuccess(response.body());
                }else {
                    collectActivityListener.onFail("Fail");
                }
            }

            @Override
            public void onFailure(Call<List<CollectActivityBean>> call, Throwable t) {
                collectActivityListener.onFail(t.toString());
            }
        });

    }
}
